﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace PhysicsProject.Infrastructure.Concrete
{
    public class DelegateCommand : ICommand
    {
        public Action Method;
        public Func<bool> Condition;

        public DelegateCommand(Action method)
        {
            Method = method;
        }

        public DelegateCommand(Action method, Func<bool> condition) : this(method)
        {
            Condition = condition;
        }

        public bool CanExecute(object parameter)
        {
            return Condition == null || Condition.Invoke();
        }

        public void Execute(object parameter)
        {
            if(parameter != null)
                Method.DynamicInvoke(parameter);
            else
                Method.Invoke();
        }

        public event EventHandler CanExecuteChanged;
    }
}
